﻿#include "ordercenter.h"
#include "ui_ordercenter.h"

OrderCenter::OrderCenter(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::OrderCenter)
{
    ui->setupUi(this);

    m_select = D_None;
    m_modelAll = new OrderManageModel;
    ui->tabView->setModel(m_modelAll);
    ui->tabView->setSelectionBehavior(QAbstractItemView::SelectRows); //整行选中的方式
    ui->tabView->horizontalHeader()->setStretchLastSection(true);
    ui->tabView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);

    QDate date = QDate::currentDate();
    ui->de_start->setDate(date);
    ui->de_end->setDate(date);
    ui->de_start->setDisplayFormat("yyyy.M.d");
    ui->de_end->setDisplayFormat("yyyy.M.d");
    ui->de_start->setCalendarPopup(true);
    ui->de_end->setCalendarPopup(true);

    on_pb_month_clicked();
}

OrderCenter::~OrderCenter()
{
    delete ui;
}

void OrderCenter::slotUpdateOrderShowForWorker()
{
    if (m_select == D_CustomizeAll)
    {
        m_modelAll->setCustomizeDay(m_startDate,m_endDate);
    }
    m_modelAll->refrushModel(m_select);
}

void OrderCenter::on_pb_today_clicked()
{
    m_select = D_TodayAll;
    slotUpdateOrderShowForWorker();
}
void OrderCenter::on_pb_yesterday_clicked()
{
    m_select = D_YesterdayAll;
    slotUpdateOrderShowForWorker();
}
void OrderCenter::on_pb_week_clicked()
{
    m_select = D_WeekAll;
    slotUpdateOrderShowForWorker();
}
void OrderCenter::on_pb_month_clicked()
{
    m_select = D_MonthAll;
    slotUpdateOrderShowForWorker();
}
void OrderCenter::on_de_start_dateChanged(const QDate &date)
{
    m_select = D_CustomizeAll;
    m_startDate = date;
    slotUpdateOrderShowForWorker();
}
void OrderCenter::on_de_end_dateChanged(const QDate &date)
{
    m_select = D_CustomizeAll;
    m_endDate = date;
    slotUpdateOrderShowForWorker();
}

void OrderCenter::on_pb_update_clicked()
{
    emit signalGainOrderAllList();
}
